# -*- coding: UTF-8 -*-

# @Time : 2020/8/21 14:14 

# @Author : litao

# @File : conf.py 

import os

class Config(object):  # 默认配置
    DEBUG = False
    log_dir = "logs"
    root_path = os.path.dirname(os.path.realpath(__file__))
    log_path = os.path.join(root_path, log_dir)
    mail_host = "smtp.qq.com"  # 设置服务器
    mail_user = "814405010@qq.com"  # 用户名
    mail_pass = "aamxrmygngvkbbfg"  # 口令   naiwbedlzmgobbff aamxrmygngvkbbfg

    sender = '814405010@qq.com'
    receivers = ['15179462795@163.com']  # 接收邮件，可设置为你的QQ邮箱或者其他邮箱
    NOWURL = ''
    # get attribute
    def __getitem__(self, key):
        return self.__getattribute__(key)

class ProductionConfig(Config):  # 生产环境
    redisip = "10.104.144.162"#"10.104.245.233"
    requestip = "10.104.109.10:9166"
    env = 'pro'
    password = 38083125
    port = 8002
    url = 'http://10.104.109.10:9166'
    configs = {
        'debug': True,
        'db': {
            'host': '127.0.0.1',
            'port': 3306,
            'user': 'root',
            'password': 'hg38083125',
            'db': 'prodata'
        },
        'session': {
            'secret': 'prodata'
        }
    }

class DevelopmentConfig(Config):  # 开发环境
    redisip = "127.0.0.1"
    requestip = "211.159.186.62:9166"
    env = 'dev'
    password = None
    port = 8002
    url = 'http://qdsoft.huaguangsoft.com'
    configs = {
        'debug': True,
        'db': {
            'host': 'saming.iok.la',
            'port': 23689,
            'user': 'root',
            'password': 'hg38083125',
            'db': 'hgsoft_base'
        },
        'session': {
            'secret': 'prodata'
        }
    }
class DevelopmentConfig1(Config):  # 开发环境
    redisip = "127.0.0.1"
    requestip = "211.159.186.62:9166"
    env = 'dev'
    password = None
    port = 28002
    url = 'http://qdsoft.huaguangsoft.com'
class DevelopmentConfig2(Config):  # 开发环境
    redisip = "127.0.0.1"
    requestip = "211.159.186.62:9166"
    env = 'dev'
    password = None
    port = 28003
    url = 'http://qdsoft.huaguangsoft.com'
class DevelopmentConfig3(Config):  # 开发环境
    redisip = "127.0.0.1"
    requestip = "211.159.186.62:9166"
    env = 'dev'
    password = None
    port = 28004
    url = 'http://qdsoft.huaguangsoft.com'
# 环境映射关系
mapping = {
    'dev': DevelopmentConfig,
    'dev1': DevelopmentConfig1,
    'dev2': DevelopmentConfig2,
    'dev3': DevelopmentConfig3,
    'pro': ProductionConfig,
    'default': DevelopmentConfig
}

# # 一键切换环境
# APP_ENV = os.environ.get('APP_ENV', 'production').lower()  # 设置环境变量为default
# config = mapping[APP_ENV]()  # 获取指定的环境

# 根据脚本参数，来决定用那个环境配置
import sys
# print(sys.argv)
num = len(sys.argv) - 1  #参数个数
if num < 1 or num > 1:
    exit("参数错误,必须传环境变量!比如: python xx.py dev|pro|default")

env = sys.argv[1]  # 环境
# print(env)
APP_ENV = os.environ.get('APP_ENV', env).lower()
config = mapping[APP_ENV]()  # 实例化对应的环境